package com.workoutgrabber.ui.model;

import java.util.LinkedList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

import com.workoutgrabber.model.Exercise;

public class ExerciseTableModel extends AbstractTableModel {
	private static String[] columnNames = {"Name", "Date"};

	private List<Exercise> exercises;

	public ExerciseTableModel(){
		this.exercises = new LinkedList<Exercise>();
	}
	
	@Override
	public int getRowCount() {
		return exercises.size();
	}
	
	@Override
	public int getColumnCount() {
		return 2;
	}
	
	@Override
	public String getColumnName(int column) {
		return columnNames[column].toString();
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		Exercise exercise = exercises.get(rowIndex);
		String rowText = "";
		
		switch (columnIndex) {
			case 0: rowText = exercise.getName(); break;
			case 1: rowText = exercise.getDate().toString(); break;
		}
		
		return rowText;
	}
	
	public void addExercise(Exercise exercise){
		exercises.add(exercise);
		fireTableDataChanged();
	}
}
